/**
 * Copyright 2009 Erick Armbrust 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 *   
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */

package tapioca.dt;

import com.google.appengine.api.datastore.Key;

/**
 * A class representing a pending put request.
 *
 * @author armbrust@gmail.com (Erick Armbrust)
 */
class PutRequest {
  private final Key key;
  private final Key shadowKey;
  private final boolean isNonNamedCreateRequest;
  
  PutRequest(Key key, Key shadowKey, boolean isNonNamedCreateRequest) {
    this.key = key;
    this.shadowKey = shadowKey;
    this.isNonNamedCreateRequest = isNonNamedCreateRequest;
  }

  public Key getKey() {
    return key;
  }

  public Key getShadowKey() {
    return shadowKey;
  }

  public boolean isNonNamedCreateRequest() {
    return isNonNamedCreateRequest;
  }
  
  @Override
  public boolean equals(Object object) {
    if (this == object) {
      return true;
    }  
      
    if (!(object instanceof PutRequest)) {
      return false;
    }
    
    PutRequest putRequest = (PutRequest) object;
    return (key != null && key.equals(putRequest.getKey())) &&
           (shadowKey != null && shadowKey.equals(putRequest.getShadowKey())) &&
           (isNonNamedCreateRequest == putRequest.isNonNamedCreateRequest());
  } 
  
  @Override
  public int hashCode() {
    final int prime = 31;
    int hash = 3;
    hash = hash * prime + ((key == null) ? 0 : key.hashCode());
    hash = hash * prime + ((shadowKey == null) ? 0 : shadowKey.hashCode());
    hash = hash * prime + (isNonNamedCreateRequest ? 1 : 0);
    return hash;
  } 
  
}
